home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
680
/
sattrack
/
ifflib20.lzh
/
Examples
/
EasyExample.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-31
|
3KB
|
109 lines
/*
EasyExample.c - A simple ILBM file viewer by Christian A. Weber
This program is in the public domain, use at your own risk.
Requires the iff.library in the LIBS: dircetory. Compiles with
Lattice C V5.04 (LC -v -L EasyExample), should also work with Manx.
*/
#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <libraries/iff.h> /* Our iff header file */
struct Library *IntuitionBase,*IFFBase, *OpenLibrary();
struct GfxBase *GfxBase;
struct NewScreen ns =
{
0,0,0,0,0,0,0, NULL, CUSTOMSCREEN|SCREENQUIET, NULL,
(STRPTR)"Simple ILBM viewer by Christian A. Weber", NULL, NULL
};
struct Screen *myscreen, *OpenScreen();
IFFFILE ifffile;
void SetOverscan(screen) /* Adjust the screen position for overscan */
register struct Screen *screen;
{
register WORD cols,rows,x=screen->Width,y=screen->Height;
register struct ViewPort *vp=&(screen->ViewPort);
cols = GfxBase->NormalDisplayColumns>>1;
rows = GfxBase->NormalDisplayRows; if(rows>300) rows>>=1;
x -= cols; if(vp->Modes & HIRES) x -= cols;
y -= rows; if(vp->Modes & LACE) y -= rows;
x >>=1; if(x<0) x=0; y >>=1; if(y<0) y=0; if(y>32) y=32;
if(vp->Modes & HAM) /* Correct overscan HAM color distortions */
{
if(GfxBase->ActiView->DxOffset-x < 96)
x=GfxBase->ActiView->DxOffset-96;
}
vp->DxOffset = -x; vp->DyOffset = -y;
MakeScreen(screen); RethinkDisplay();
}
void Fail(text) /* Print error message, free resources and exit */
char *text;
{
printf("%s, IFFError = %ld\n",text,IFFError());
if(ifffile) CloseIFF(ifffile);
if(myscreen) CloseScreen(myscreen);
if(IFFBase) CloseLibrary(IFFBase); /* MUST ALWAYS BE CLOSED !! */
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase);
exit(0);
}
void main(argc,argv)
int argc;
char **argv;
{
register LONG count,i;
struct BitMapHeader *bmhd;
UWORD colortable[128];
if((argc != 2) || !strcmp(argv[1],"?")) {
printf("Format: %s filename\n",argv[0]);
exit(20);
}
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
IntuitionBase = OpenLibrary("intuition.library",0L);
if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
printf("Copy the iff.library to your LIBS: directory!\n");
exit(10);
}
printf("Loading file %s ... ",argv[1]);
if(!(ifffile=OpenIFF(argv[1]))) Fail("Error opening file");
if(!(bmhd=GetBMHD(ifffile))) Fail("BitMapHeader not found");
ns.Width = bmhd->w;
ns.Height = bmhd->h;
ns.Depth = bmhd->nPlanes;
ns.ViewModes = GetViewModes(ifffile);
if(!(myscreen = OpenScreen(&ns))) Fail("Can't open screen!");
SetOverscan(myscreen);
count = GetColorTab(ifffile,colortable);
if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
LoadRGB4(&(myscreen->ViewPort),colortable,count);
if(!DecodePic(ifffile,&myscreen->BitMap)) Fail("Can't decode picture");
for(i=0; i<100; ++i)
{
if(!((*((UBYTE*)0xbfe001))&64)) break; /* Don't use this in your code! */
Delay(5L);
}
Fail("done"); /* Normal termination */
}